import store from '@/store'

export default {
    name: 'Permission',
    functional: true,
    props: {
        value: {
            type: [String, Array],
            default: ''
        }
    },
    computed: {
        test () {
            return this.value
        }
    },
    render: function (_, { props, slots }) {
        const $slots = slots()
        const role = Number(store.state.user.roleType)
        const roles = Array.isArray(props.value)
            ? props.value
            : props.value.split(',')
        if (roles.findIndex(item => Number(item) === role) < 0) {
            return null
        }
        return $slots.default
    }
}

/**
 * 使用
 * <Permission value="1,2,3"
 * or
 * <Permission :value="[1,2,3,4]"
 */
